import Vue from "vue";
import Vuex from "vuex";

//仿数据库数据

const userList = require("../../../service/store/userList.json");
const fastReply = require("../../../service/store/fastReply.json");
const productList = require("../../../service/store/product.json");
const messageList = require("../../../service/store/messageList.json");
const robotReply = require("../../../service/store/robotReply.json");

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    islogin: sessionStorage.getItem("islogin"), // 用于保存是否已登录
    phone: sessionStorage.getItem("phone"), // 用于保存当前登录用户名
    uid: sessionStorage.getItem("uid"), // 用于保存当前登录用户名
    lid: sessionStorage.getItem("lid"),
    avatar: sessionStorage.getItem("avatar"),
    /***客服回复 */
    userList: userList,
    fastReply: fastReply,
    productList: productList,
    messageList: messageList,
    robotReply: robotReply,
  },
  mutations: {
    /** 当登录成功后可以调用
     *  修改登录状态，将传入的当前登录用户名存入state */
    loginok(state, phone, uid, lid, uploader, avatar) {
      state.islogin = true;
      state.phone = phone;
      state.uid = uid;
      state.lid = lid;
      state.avatar = avatar;
    },
    logout(state, islogin) {
      state.islogin = false;
    },
  },
  actions: {},
  modules: {},
});
